package com.wh.wisdomsite.xbox.server.customTags;

import com.wh.wisdomsite.xbox.ba.entity.Menu;
import com.wh.wisdomsite.xbox.server.util.UserUtils;
import net.sf.json.JSONObject;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.util.Map;

/**
 * 权限标识TAG处理类
 *
 * @version V1.0
 * @Package: com.wh.wisdomsite.xbox.server.customTags
 * @author: 丁奕
 * @date: 2018-08-30 17:06
 * @Copyright 公司版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2016
 **/
public class PermissionTag extends SimpleTagSupport {

    /**
     * 权限标识
     */
    private String permission;

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public void doTag() throws JspException, IOException {
        JspWriter out = getJspContext().getOut();
        Map<String, Menu> permissionMap = UserUtils.getServerSessionUser().getPermissions();
        if(permissionMap.containsKey(permission)){
            Menu menu = permissionMap.get(permission);
            JSONObject menuJson = JSONObject.fromObject(menu);
            out.write(menuJson.toString());
        }else{
            out.write("false");
        }
    }
}
